package cms.manage.template.value.impl;

import cms.bean.template.Forum;
import cms.manage.template.impl.FavoriteTemplateManage;
import cms.manage.template.value.TplValueStrategy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

import static cms.common.SystemConstant.DisplayType.DISPLAY_COLLECTION;
import static cms.common.SystemConstant.DisplayType.DISPLAY_ENTITYBEAN;

@Service("收藏夹")
public class FavoriteStrategy implements TplValueStrategy {

    @Resource
    FavoriteTemplateManage favoriteTemplateManage;//收藏夹 -- 模板方法实现

    @Override
    public Object doOperation(Forum forum, Map submitParameter, Map runtimeParameter) {
        if(forum.getForumChildType().equals("加入收藏夹")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = favoriteTemplateManage.addFavoriteCollection(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("话题会员收藏总数")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Long value = favoriteTemplateManage.favoriteCountEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("用户是否已经收藏话题")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Boolean value = favoriteTemplateManage.alreadyCollectedEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("问题会员收藏总数")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Long value = favoriteTemplateManage.questionFavoriteCountEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("用户是否已经收藏问题")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Boolean value = favoriteTemplateManage.alreadyFavoriteQuestionEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }
        return null;
    }
}
